﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
using System.Data.Sql;
using System.Data.SqlTypes;


namespace SmartTestManager_1._0
{
    public partial class adminMainForm : Form
    {
        String ConnectionStr = @"data source=.;initial catalog =TM;Integrated security=true;";
        SqlConnection Connection;
        SqlCommand sqlCmd;
        SqlDataReader DataReader;
        SqlDataAdapter DataAdapter;
        DataSet dataset;
        
        
        public adminMainForm()
        {
            InitializeComponent();
            splitContainer1.Panel2.Enabled = false;
            splitContainer1.Panel1.Enabled = false;
            
        }

        private void createNewReportToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void createNewTestSuiteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            splitContainer1.Panel1.Enabled = true;
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            AssignmentConfirmation asConf = new AssignmentConfirmation();
            splitContainer1.Panel1.Enabled = false;
            splitContainer1.Panel2.Enabled = true;
        }

        private void adminMainForm_Load(object sender, EventArgs e)
        {
            try
            {
                Connection = new SqlConnection(ConnectionStr);
                DataAdapter = new SqlDataAdapter("select * from TestSuite", Connection);
                dataset = new DataSet();
                DataTable datatable = new DataTable("Projects");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Projects"]);
                this.projectsComboBox.DataSource = dataset.Tables["Projects"];
                this.projectsComboBox.DisplayMember = "TS_name";
                this.projectsComboBox.ValueMember = "TS_id";
            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }


            try
            {
                Connection = new SqlConnection(ConnectionStr);
                DataAdapter = new SqlDataAdapter("select * from Testers", Connection);
                dataset = new DataSet();
                DataTable datatable = new DataTable("Testers");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Testers"]);
                this.testerSelectionComboBox.DataSource = dataset.Tables["Testers"];
                this.testerSelectionComboBox.DisplayMember = "Name";
                this.testerSelectionComboBox.ValueMember = "T_id";
            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }



        }

        private void projectsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnShowReq_Click(object sender, EventArgs e)
        {
            try
            {
                Connection = new SqlConnection(ConnectionStr);
                sqlCmd = new SqlCommand("select * from Requriments where TS_id= @ts_id", Connection);
                DataAdapter = new SqlDataAdapter(sqlCmd);

                SqlParameter param_ts_id = new SqlParameter("@ts_id", SqlDbType.Int);
                param_ts_id.Direction = ParameterDirection.Input;
                param_ts_id.Value = projectsComboBox.SelectedValue;
                sqlCmd.Parameters.Add(param_ts_id);

                dataset = new DataSet();
                DataTable datatable = new DataTable("Requirements");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Requirements"]);

                reqsListBox.DataSource = dataset.Tables["Requirements"];
                reqsListBox.DisplayMember = "Req_title";
                reqsListBox.ValueMember = "Req_id";


                /*
                dataset = new DataSet();
                DataTable datatable = new DataTable("Employees");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Employees"]);
                */

            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void OKButton_Click_1(object sender, EventArgs e)
        {
            splitContainer1.Panel1.Enabled = false;
            splitContainer1.Panel2.Enabled = true;
            label2.Text = testerSelectionComboBox.Items[testerSelectionComboBox.SelectedIndex].ToString();
            //listBox1.Items.AddRange(reqsListBox.SelectedItems);
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            splitContainer1.Panel1.Enabled = true;
            splitContainer1.Panel2.Enabled = false;

        }

        private void btnShowReq_Click_1(object sender, EventArgs e)
        {
            try
            {
                Connection = new SqlConnection(ConnectionStr);
                sqlCmd = new SqlCommand("select * from Requriments where TS_id= @ts_id", Connection);
                DataAdapter = new SqlDataAdapter(sqlCmd);

                SqlParameter param_ts_id = new SqlParameter("@ts_id", SqlDbType.Int);
                param_ts_id.Direction = ParameterDirection.Input;
                param_ts_id.Value = projectsComboBox.SelectedValue;
                sqlCmd.Parameters.Add(param_ts_id);

                dataset = new DataSet();
                DataTable datatable = new DataTable("Requirements");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Requirements"]);

                reqsListBox.DataSource = dataset.Tables["Requirements"];
                reqsListBox.DisplayMember = "Req_title";
                reqsListBox.ValueMember = "Req_id";


                /*
                dataset = new DataSet();
                DataTable datatable = new DataTable("Employees");
                dataset.Tables.Add(datatable);
                DataAdapter.Fill(dataset.Tables["Employees"]);
                */

            }

            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void testRequirementsReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TestRequirementsReport Trr = new TestRequirementsReport();
            Trr.ShowDialog();
        }
    }
}
